package pl.Ventana;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import pl.Ventana.*;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
 
public class Ventana extends Frame {
 boolean inAnApplet = true;
 private static String textArea;
 private static String file;
 
@SuppressWarnings("deprecation")
public static void main(String args[]) {
 Ventana window = new Ventana();
 window.inAnApplet = false;
 window.setTitle("Ejemplo");
 window.pack();
 window.show();
 }

public static void setFile(String s){
	file=s;
}

public static String getFile() {
	return file;
}


public static void settextArea(String s){
	textArea=s;
}

public static String gettextArea() {
	return textArea;
}

public static void appendtextArea(String s){
	textArea=textArea+s;
}

public Ventana() {
 final Panel panelAlto = new Panel();
 panelAlto.add("West", new Label("Texto a procesar", Label.CENTER));
 setFile("");
 final TextArea textFile= new TextArea(gettextArea(), 20, 100);
 
 panelAlto.add("West", new TextField(getFile(),20));
 JButton boton = new JButton("Cargar");
 panelAlto.add("West", boton);
 //boton.addActionListener();
 boton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			//ventanaPrincipal.setVisible(false);
			panelAlto.setVisible(false);
			//ventanaSecundaria.setVisible(true);
			JFileChooser chooser = new JFileChooser();
			 chooser.setApproveButtonText("Abrir TxT");
			 chooser.addChoosableFileFilter(new TxTFilter());
			 chooser.showOpenDialog(null);
			 File archivo=chooser.getSelectedFile();
			 try {
			 BufferedReader reader = new BufferedReader(new FileReader(archivo));
			 String linea = reader.readLine();
			 while (linea != null) {
			 //jTextArea1.append(linea + "\n");
				 appendtextArea(linea+"\n");
			 linea = reader.readLine();
			 }
			 } catch (Exception ex) {
			 }
			 panelAlto.add("East", textFile );
			panelAlto.setVisible(true);
		}
 });
  //settextArea("");
 

 add("North", panelAlto);
 
Panel panelBajo = new Panel();
panelBajo.add("West", new Button("Compilador 1"));
panelBajo.add("West", new Button("Compilador 2"));
panelBajo.add("West", new Button("Compilador 3"));
 add("South",panelBajo);
 }
 
@SuppressWarnings("deprecation")
public boolean handleEvent(Event ev) {
 if (ev.id == Event.WINDOW_DESTROY) {
 if (inAnApplet) {
 dispose();
 } else {
 System.exit(0);
 }
 }
 return super.handleEvent(ev);
 }
 } 